import { Component, OnInit } from '@angular/core';
import { HttpService } from '@core/services/http.service';
import {ActivatedRoute, Router} from '@angular/router';

@Component({
  selector: 'app-class-drill',
  templateUrl: './class-drill.component.html',
  styleUrls: ['./class-drill.component.less']
})
export class ClassDrillComponent implements OnInit {

  data = [];  // 演练数据
  loading = false;
  total = 0; // 总数据条数
  Pi = 1;  // 页码
  Ps = 10;  // 每页数量
  key = ''; // 检索关键字
  user_id = JSON.parse(localStorage.getItem('_user')).user_id;

  constructor(public http: HttpService,
              private ActiveRoute: ActivatedRoute,
              public router: Router) { }

  ngOnInit() {
    this.getData(this.key, this.Pi, this.Ps, this.user_id);
  }

  refreshData() {
      this.getData(this.key, this.Pi, this.Ps, this.user_id);
  }

  getData(key, pi, ps, u_id) {
    this.http.getExercisesList({key: key, pi: pi, ps: ps,u_id:u_id}).subscribe(res => {
       if (res.list && res.list.length) {
           this.data = res['list'];
           this.total = res['total'];
       }
    });
  }
  preview(p_id,isCloud,isUse) {
      this.router.navigate(['../advance'], {relativeTo: this.ActiveRoute, queryParams: { p_id: p_id ,isCloud:isCloud ,isUse:isUse}});
  }

}
